/*	=======================================================================	*/
/// <remarks>
/// Version:
///		- number:	1.0.4
///		- build:	20060605
///		- status:	dev
/// </remarks>
/*	=======================================================================	*/
/// <remarks>
/// Global Variables
/// </remarks>
	try {
		var x_debug = false;
		var x_dialog = new X_DialogLink(x_debug, window.parent.InnerDialogLoaded(), "linkText");
		window.onload = x_dialog.Loader;
	} catch (e) {
		alert("Error:"+e.description);
	}
	
/*	=======================================================================	*/
/// <remarks>
/// Class: X_DialogLink
/// The X_DialogLink object class has the following purpose/function:
///	- this is a javascript class for all xed dialogs
/// </remarks>
/*	-----------------------------------------------------------------------	*/
/// <summary>
/// The X_DialogLink object class is constructed as follows:
///		var thisobj = new X_DialogLink(dbg);
/// - where:
///		- dbg:	debugging switch
/// </summary>
function X_DialogLink(dbg, fck, lnk) {
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Public</remarks>
	/*	-------------------------------------------	*/
	this.parameter = "";
	/*	-------------------------------------------	*/
	/// <remarks>Properties: Private</remarks>
	/*	-------------------------------------------	*/
	// Gets the document DOM
	var _ed = fck;
	var _fck;
	var _dom;
	var _cfg;
	var _doc = document;
	var _win = window;
	var _self = this;	// self allows for a method/property to be called internally
	var _debug = (dbg)? dbg : false;
	var _id = "X_DialogLink";
	// string constants for links:
	var _link_el = null;	// The actual selected link in the editor.
	var _link_web = "http://";
	var _link_pop = "Popup";
	var _link_webpop = "javascript:Popup('http://";
	var _link_eml = "mailto:";
	var _link_lnk = "default.aspx?link=";
	var _link_doc = "documents/";
	var _link_id = (lnk)? lnk : "linkText";
	
	var _common = new X_Common(dbg);
	/*	-------------------------------------------	*/
	/// <remarks>Region: Accessor methods</remarks>
	/*	-------------------------------------------	*/
	this.GetID = function() { return(_id); }
	/*	-------------------------------------------	*/
	/// <remarks>Region: Public methods</remarks>
	/*	-------------------------------------------	*/
	this.Create = _Create;
	this.Loader = _Loader;
	this.Cancel = _Cancel;
	this.SetLink = _SetLink;
	this.GetLink = _GetLink;
	/// <summary>Method:_Create</summary>
	function _Create(thisar) {
		_Debug("_Create:");
	}
	/// <summary>Method:_Loader</summary>
	function _Loader() {
		_Debug("_Loader:");
		_fck = _ed.FCK ;
		_dom = _ed.FCK.EditorDocument ;
		_cfg = _ed.FCKConfig;
		_GetLink()
		_Debug("_Loader", "_link_el", _link_el);
	}
	/// <summary>Method:_Cancel</summary>
	function _Cancel(retval) {
		_Debug("_Cancel:", "retval", retval);
		_win.returnValue = (retval)? retval : null ;
		_win.close() ;
	}
	/// <summary>Method:_SetLink</summary>
	function _SetLink(urlid) {
		_Debug("_SetLink:", "urlid", urlid);
		var sUrl = _getEl(urlid).value;
		_Debug("_SetLink:", "sUrl", sUrl);
		
		if (_getEl('linkType_web').checked == true)
			sUrl = _link_web + sUrl;
		else if (_getEl('linkType_webpop').checked == true)
			sUrl = _link_webpop + sUrl + "')";
		else if (_getEl('linkType_email').checked == true)
			sUrl = _link_eml + sUrl;
		else if (_getEl('linkType_link').checked == true)
			sUrl = _link_lnk + sUrl;
		else if (_getEl('linkType_doc').checked == true)
			sUrl = _link_doc + sUrl;
		
		_Debug("_SetLink:", "sUrl", sUrl);
		
		if (_link_el) {	// Modifying an existent link.
			_ed.FCKUndo.SaveUndoStep() ;
			_link_el.href = sUrl ;
		} else {		// Creating a new link.
			_link_el = _ed.FCK.CreateLink(sUrl) ;
			if (!_link_el)
				return true ;
		}
		_common.SetAttribute(_link_el, '_fcksavedurl', sUrl) ;
		
		_Cancel() ;
	}
	/// <summary>Method:_GetLink</summary>
	function _GetLink() {
		_Debug("_GetLink:");
		getSelectionLink() ;
		if (_link_el != null) {
			var lnktxt, lnkval = _link_el.getAttribute("href",2);
			_Debug("_GetLink", "lnkval", lnkval);
			if (lnkval.indexOf(_link_web) >= 0) {
				var popstt = lnkval.indexOf(_link_pop);
				_Debug("_GetLink", "popstt", popstt);
				if (popstt >= 0) {
					lnktxt = lnkval.substr(popstt+_link_pop.length+2);
					lnktxt = lnktxt.substr(0, lnktxt.length-2);
					_getEl('linkType_webpop').checked = true;
				} else {
					lnktxt = lnkval.substr(_link_web.length);
					_getEl('linkType_web').checked = true;
				}
			} else if (lnkval.indexOf(_link_eml) >= 0) {
				lnktxt = lnkval.substr(_link_eml.length);
				_Debug("_GetLink", "lnktxt", lnktxt);
				_getEl('linkType_email').checked = true;
			} else if (lnkval.indexOf(_link_lnk) >= 0) {
				lnktxt = lnkval.substr(_link_lnk.length);
				_getEl('linkType_link').checked = true;
			} else if (lnkval.indexOf(_link_doc) >= 0) {
				lnktxt = lnkval.substr(_link_doc.length);
				_getEl('linkType_doc').checked = true;
			} else {
				lnktxt = lnkval;
				//_getEl('linkType_other').checked = true;
			}
			_getEl(_link_id).value = lnktxt;
		}
	}
	/*	-------------------------------------------	*/
	/// <remarks>Region: Private methods</remarks>
	/*	-------------------------------------------	*/
	var _getEl = function(el) {return _doc.getElementById(el);}
	/// <summary>Method:getSelectionLink</summary>
	function getSelectionLink() {
		_link_el = _fck.Selection.MoveToAncestorNode('A') ;
		if (_link_el)
			_fck.Selection.SelectNode(_link_el) ;
	}
	/// <summary>Method:_RaiseError</summary>
	function _RaiseError(thiserr) {
		_Debug("RaiseError:", "thiserr", thiserr);
		throw (thiserr);
	}
	/// <summary>Method:_Debug - write debugging message. First param is the method label, followed by name, value pairs</summary>
	function _Debug(arg) {
		if (_debug) {
			s = "<!-- " + _id + "::"
			s = s.concat(arguments[0], ":");
			var argn = arguments.length;
			for(var i=1; i<argn; i=i+2)
				s = s.concat(arguments[i], ":", arguments[i+1], " ");
			alert(s.concat("-->\n"));
		}
	}
	
}
